package com.example.dicos.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.Data;
import org.apache.ibatis.reflection.MetaObject;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Date;

/**
 * @description:
 * @author: 朱超
 * @createDate: 2022/5/12
 * @version: 1.0
 * @remark：备注
 */
@Data
@EnableTransactionManagement
@Configuration // 配置类
@MapperScan("com.example.dicos.mapper")
public class MyBatisPlusConfig implements MetaObjectHandler {

    //插入时间的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("creationTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    //更新时间的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
